package com.baoyouqun.controller.back;

import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baoyouqun.base.PageResponse;
import com.baoyouqun.domain.CreateCmd.UserPointsCreateCmd;
import com.baoyouqun.domain.Query.UserPointsQuery;
import com.baoyouqun.domain.UpdateCmd.UserPointsUpdateCmd;
import com.baoyouqun.domain.VO.UserPointsVO;
import com.baoyouqun.service.UserPointsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/back/userPoints")
@Api(tags = "用户积分表管理接口")
public class UserPointsController {

    @Resource
    private UserPointsService userPointsService;

    @PostMapping("create")
    @ApiOperation("新增用户积分表")
    public SingleResponse<UserPointsVO> create(UserPointsCreateCmd cmd) {
        return userPointsService.create(cmd);
    }

    @PutMapping("update")
    @ApiOperation("修改用户积分表")
    public Response update(UserPointsUpdateCmd cmd) {
        return userPointsService.update(cmd);
    }

    @DeleteMapping("delete")
    @ApiOperation("根据ID删除用户积分表")
    public Response delete(String id) {
        StpUtil.checkRole("R010000");
        userPointsService.removeById(id);
        return Response.buildSuccess();
    }

    @GetMapping("getById")
    @ApiOperation("根据ID查询用户积分表")
    public SingleResponse<UserPointsVO> selectById(String id) {
        return SingleResponse.of(userPointsService.selectById(id));
    }

    @GetMapping("page")
    @ApiOperation("分页查询用户积分表")
    public PageResponse<UserPointsVO> page(UserPointsQuery query) {
        IPage<UserPointsVO> page = userPointsService.pageVo(query);
        return PageResponse.of(page.getRecords(), page.getTotal(), page.getCurrent(), page.getSize());
    }
}